<template>
  <!-- 品势章节设置子组件 -->
  <div class="change_admin">
    <el-dialog
      :title="title"
      class="gl_dialog_TitleLine"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="500px"
    >
      <el-form ref="form" class="gl_form_mini" :model="SiSTKWEventsManagementPoomsaeSettingDto" :rules="ChapterSettingsVO_Rules" label-width="80px" label-position="right" style="padding-right: 30px;">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="章节名称" prop="name">
              <el-input v-model="SiSTKWEventsManagementPoomsaeSettingDto.name" size="mini" clearable />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="close()">取消</el-button>
        <el-button type="primary" size="mini" @click="saveNew('form')">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { SiSTKWEventsManagementPoomsaeSettingDto } from '@/lib/form/game/swaggerForm';
import { ChapterSettingsVO_Rules } from '@/lib/validate/configuration/index.js';
import { CopyData } from '@/lib';
import { api_GET_EventsManagementPoomsaeSetting } from '@/extend/api/gameswaggerApi/app.js';
export default {
  name: 'Account',
  data() {
    return {
      SiSTKWEventsManagementPoomsaeSettingDto: new SiSTKWEventsManagementPoomsaeSettingDto(),
      ChapterSettingsVO_Rules: new ChapterSettingsVO_Rules(),
      title: '', // 表单表头
      dialogVisible: false,
      tableData: [], // 表格数据
      inputDataName: ''// 获取表单框内输入的名称，判断其唯一性
    };
  },
  watch: {
    // 监听表单窗口状态如果关闭则清除提示信息
    dialogVisible(val) {
      if (!val) {
        this.$refs['form'].resetFields();
      }
    }
  },
  methods: {
    // 获取数据
    freshData() {
      api_GET_EventsManagementPoomsaeSetting().then(res => {
        this.tableData = res.items;
      });
    },
    open(row) {
      if (row) {
        this.title = '编辑';
        this.SiSTKWEventsManagementPoomsaeSettingDto = JSON.parse(JSON.stringify(row));
        this.inputDataName = JSON.parse(JSON.stringify(row.name));
      } else {
        this.title = '新增';
        this.SiSTKWEventsManagementPoomsaeSettingDto = JSON.parse(JSON.stringify(new SiSTKWEventsManagementPoomsaeSettingDto()));
      }
      this.dialogVisible = true;
    },
    close() {
      this.dialogVisible = false;
    },
    // 点击确定进行添加或者编辑的操作
    saveNew(formName) {
      const returnData = new SiSTKWEventsManagementPoomsaeSettingDto();
      CopyData(this.SiSTKWEventsManagementPoomsaeSettingDto, returnData);
      console.log(returnData);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.title === '新增') {
            this.$emit('pushTabelData', returnData);
          } else {
            var editData = JSON.parse(JSON.stringify(this.SiSTKWEventsManagementPoomsaeSettingDto));
            if (this.inputDataName === this.SiSTKWEventsManagementPoomsaeSettingDto.name) {
              this.dialogVisible = false;
            } else {
              this.$emit('editTabelData', editData, editData.name);
            }
          }
        } else {
          return false;
        }
      });
    }
  }
};
</script>

